package com.platform.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.platform.dao.ApiActivitySignMapper;
import com.platform.entity.ContractTplVo;
import com.platform.entity.activity.ActivitySign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 活动参与 service
 * @Author jaalemon@163.com
 * @Date 2021/7/12 18:53
 * @Version 1.0
 */
@Service
public class ApiActivitySignService {

    @Autowired
    private ApiActivitySignMapper apiActivitySignMapper;

    /**
     * 获取代理商提交会员申请的活动
     * @param sendUserId
     * @param recvUserId
     * @return
     */
    public ActivitySign getActivitySigned(Long sendUserId, Long recvUserId){

        QueryWrapper<ActivitySign> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("send_user_id", sendUserId);
        queryWrapper.eq("recv_user_id", recvUserId);
        ActivitySign activitySign = apiActivitySignMapper.selectOne(queryWrapper);

        return activitySign;
    }

    /**
     * 获取会员是否有未参与的活动名额
     * @param recvUserId
     * @return
     */
    public ActivitySign getActivityNotBuy(Long recvUserId){

        QueryWrapper<ActivitySign> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("recv_user_id", recvUserId);
        queryWrapper.eq("status", 1);// 未参与
        ActivitySign activitySign = apiActivitySignMapper.selectOne(queryWrapper);

        return activitySign;
    }

    /**
     * 保存活动
     * @param activitySign
     */
    public void save(ActivitySign activitySign){
        apiActivitySignMapper.insert(activitySign);
    }

    /**
     * 更新活动
     * @param activitySign
     */
    public void update(ActivitySign activitySign){
        apiActivitySignMapper.updateById(activitySign);
    }

}
